home *** CD-ROM | disk | FTP | other *** search
- /* VMRIO/CCC
- * virtual memory random I/O asm lang file
- *
- * Copyright 1983 by Jim Kyle - All Rights Reserved
- * Licensed for individual non-commercial use only.
- *
- * created: November 16, 1983 - Jim Kyle
- * last changed: November 23, 1983 - Jim Kyle
- */
-
- /*
- * sec_seek(), fread(), and fwrite() are tailored exact-
- * ly to LC and the LDOS 5.1.x system (Model 3), and
- * will require modification to work with other systems.
- * The sec_seek() function is totally non-K&R; the other
- * two functions are exactly like the read() and write()
- * functions described in the K&R book in Chapter
- * 8, except that both use file POINTERS rather than
- * file DESCRIPTORS to identify the file.
- */
-
- sec_seek(fp,sec) FILE *fp; int sec; /* sector SEEK */
- {
- #asm
- $GA HL,BC ;recover arg values (LC macro)
- LD E,(HL)
- INC HL
- LD D,(HL)
- INC DE ;to FCB itself
- CALL 4442H ;DOS @POSN routine
- LD HL,0 ;return OK if no err
- RET Z
- CP 28 ;end of file?
- RET Z
- CP 29 ;past end of file?
- RET Z
- CALL @ERRET ;else report error
- LD HL,-2 ;and return ERR
- #endasm
- }
-
- fread(fp,bfr,n) FILE *fp; char *bfr; int n;
- {
- #asm
- $GA HL,DE,BC ;get args (LC macro)
- CALL @GINT ;get LC FCB adr into HL
- INC HL ;to FCB
- EX DE,HL ;HL=buf, DE=fcb, BC=n
- INC BC ;because of decr in test
- PUSH BC ;to stack
- LD BC,0 ;actual char count
- JR FREAD3
- FREAD1
- EX (SP),HL
- CALL 0013H ;DOS @GET routine
- JR Z,FREAD2
- LD BC,-1 ;error return value
- JR FREAD4
- FREAD2
- LD (HL),A
- INC HL
- INC BC ;the count
- FREAD3
- EX (SP),HL ;swap 'n' and 'buf'
- DEC HL
- LD A,H
- OR L
- JR NZ,FREAD1 ;not done yet
- FREAD4
- POP HL ;clean up stack
- LD H,B
- LD L,C ;count of actual transfer
- #endasm
- }
-
- fwrite(fp,bfr,n) FILE *fp; char *bfr; int n;
- {
- #asm
- $GA HL,DE,BC
- CALL @GINT ;get LC FCB adr into HL
- INC HL ;to true FCB adr
- EX DE,HL ;HL=buf, DE=fcb, BC=n
- INC BC ;because of decr in test
- PUSH BC ;to stack
- LD BC,0 ;actual char count
- JR FWRT2
- FWRT1
- EX (SP),HL ;get buf adr back into HL
- LD A,(HL)
- INC HL
- CALL 001BH ;DOS @PUT routine
- JR NZ,FWRT3 ;in case of any error
- INC BC ;the count
- FWRT2
- EX (SP),HL ;swap 'n' and 'buf'
- DEC HL
- LD A,H
- OR L
- JR NZ,FWRT1 ;not done yet
- FWRT3
- POP HL ;clean up stack
- LD H,B
- LD L,C ;count of actual transfer
- #endasm
- }
-
-